home *** CD-ROM | disk | FTP | other *** search
/ Acorn User: China / Acorn User China CD-ROM (UK) (Disc A) / Acorn User China CD-ROM (UK) (Disc A).bin / DEMON / DEVELOPER / HYPERMAIL.ARC / !hypermail_c_strcasecmp < prev    next >
Encoding:
Text File  |  1996-01-23  |  3.8 KB  |  98 lines

  1. /*
  2.  * ++Copyright++ 1985
  3.  * -
  4.  * Copyright (c) 1985 Regents of the University of California.
  5.  * All rights reserved.
  6.  */
  7.  
  8. /*
  9. #include "../conf/portability.h"
  10. */
  11.  
  12. #define NEED_STRCASECMP
  13. #ifdef NEED_STRCASECMP
  14.  
  15. /*
  16. #include <sys/types.h>
  17. */
  18. #include <ctype.h>
  19. #include <string.h>
  20.  
  21. #include "OS:types.h"
  22.  
  23. /*
  24.  * This array is designed for mapping upper and lower case letter
  25.  * together for a case independent comparison.  The mappings are
  26.  * based upon ascii character sequences.
  27.  */
  28. static const u_char charmap[] = {
  29.         '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
  30.         '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
  31.         '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
  32.         '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
  33.         '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047',
  34.         '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057',
  35.         '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067',
  36.         '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077',
  37.         '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
  38.         '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
  39.         '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
  40.         '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137',
  41.         '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
  42.         '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
  43.         '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
  44.         '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177',
  45.         '\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207',
  46.         '\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217',
  47.         '\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227',
  48.         '\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237',
  49.         '\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247',
  50.         '\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257',
  51.         '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267',
  52.         '\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277',
  53.         '\300', '\301', '\302', '\303', '\304', '\305', '\306', '\307',
  54.         '\310', '\311', '\312', '\313', '\314', '\315', '\316', '\317',
  55.         '\320', '\321', '\322', '\323', '\324', '\325', '\326', '\327',
  56.         '\330', '\331', '\332', '\333', '\334', '\335', '\336', '\337',
  57.         '\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
  58.         '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
  59.         '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
  60.         '\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377',
  61. };
  62.  
  63. int
  64. strcasecmp(s1, s2)
  65.         const char *s1, *s2;
  66. {
  67.         register const u_char *cm = charmap,
  68.                         *us1 = (const u_char *)s1,
  69.                         *us2 = (const u_char *)s2;
  70.  
  71.         while (cm[*us1] == cm[*us2++])
  72.                 if (*us1++ == '\0')
  73.                         return (0);
  74.         return (cm[*us1] - cm[*--us2]);
  75. }
  76.  
  77. int
  78. strncasecmp(s1, s2, n)
  79.         const char *s1, *s2;
  80.         register size_t n;
  81. {
  82.         if (n != 0) {
  83.                 register const u_char *cm = charmap,
  84.                                 *us1 = (const u_char *)s1,
  85.                                 *us2 = (const u_char *)s2;
  86.  
  87.                 do {
  88.                         if (cm[*us1] != cm[*us2++])
  89.                                 return (cm[*us1] - cm[*--us2]);
  90.                         if (*us1++ == '\0')
  91.                                 break;
  92.                 } while (--n != 0);
  93.         }
  94.         return (0);
  95. }
  96. #endif /*NEED_STRCASECMP*/
  97.                                                                                                                                                                
  98.